import { baseApiUrl, path } from "../../utils/config";
import { userPileowner } from '../../utils/api';
import Toast from '@vant/weapp/toast/toast';
const app = getApp();
Page({
  data: {
    baseImageUrl: baseApiUrl,
    placeholderStyle: "font-size: 28rpx;color: #CACACA; font-weight:200;",

    name: "",
    phone: "",
    address: "",

    province: "",
    city: "",
    area: "",

    province_id: "",
    city_id: "",
    area_id: "",

    region: "",
    value: [],

    phone_list: ["+86"],

    checked: false
  },
  onLoad(options) { },
  bindRegionChange(e) {
    let { value, code } = e.detail;
    let [province, city, area] = value;
    let [province_id, city_id, area_id] = code;
    let region = `${province}${city}${area}`;
    this.setData({ province, city, area, province_id, city_id, area_id, region });
  },
  changeChecked() {
    this.setData({ checked: !this.data.checked });
  },
  router(e) {
    let { url } = e.currentTarget.dataset;
    wx.navigateTo({ url });
  },
  async submit() {
    let { checked } = this.data;
    if (!checked) {
      Toast('需同意说明条款');
      return false;
    }
    let data = {
      name: this.data.name,
      phone: this.data.phone,
      address: this.data.address
    };
    await userPileowner(data);
    Toast.success('提交成功');
  },
  onShareAppMessage() {
    let poster = app.globalData.poster;
    return {
      path,
      imageUrl: poster
    }
  },
  onShareTimeline() { }
})